﻿using System.Linq;
using System.Web.Mvc;

namespace CodeContrib.Web.Mvc
{
	public class PartialValidationAttribute : ActionFilterAttribute
	{
		public override void OnActionExecuting(ActionExecutingContext filterContext)
		{
			var modelState = filterContext.Controller.ViewData.ModelState;
			var valueProvider = filterContext.Controller.ValueProvider;

			foreach (var key in modelState.Keys.Where(x => !valueProvider.ContainsPrefix(x)))
			{
				modelState[key].Errors.Clear();
			}
		}
	}
}